package com.henry.chatkit.messages.holder

import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.henry.chatkit.R
import com.henry.chatkit.messages.MessageInfo
import com.henry.chatkit.utils.TimeUtils

abstract class MessageEmptyHolder(itemView: View) : MessageBaseHolder(itemView) {

    var chatTimeText: TextView = itemView.findViewById(R.id.chat_time_tv)
    var msgContentFrame: FrameLayout = itemView.findViewById(R.id.msg_content_fl)

    init {
        initVariableLayout()
    }

    abstract fun getVariableLayout(): Int

    abstract fun initVariableViews()

    private fun initVariableLayout() {
        if (getVariableLayout() != 0) {
            setVariableLayout(getVariableLayout())
        }
    }

    private fun setVariableLayout(resId: Int) {
        if (msgContentFrame.childCount == 0) {
            View.inflate(rootView.context, resId, msgContentFrame)
        }
        initVariableViews()
    }

    override fun layoutViews(msg: MessageInfo?, position: Int) {

        if (mAdapter == null || msg == null) {
            return
        }

        //// 时间线设置
        val time: Long = msg.msgTime
        if (properties.chatTimeBubble != null) {
            chatTimeText.background = properties.chatTimeBubble
        }
        if (properties.chatTimeFontColor != 0) {
            chatTimeText.setTextColor(properties.chatTimeFontColor)
        }
        if (properties.chatTimeFontSize != 0) {
            chatTimeText.textSize = properties.chatTimeFontSize.toFloat()
        }

        if (msg.showTime) {
            chatTimeText.visibility = View.VISIBLE
            chatTimeText.text = TimeUtils.getTime(time)
        } else {
            chatTimeText.visibility = View.GONE
        }

    }

}